package org.jackysoft.webapp;

import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

import org.jackysoft.config.CommonConfig;
import org.jackysoft.config.WebMvcConfig;
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.util.Log4jConfigListener;
import org.springframework.web.util.WebAppRootListener;

public class JackyWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

	static final Logger logger = LoggerFactory.getLogger(JackyWebApplicationInitializer.class);	
	@Override
	public void onStartup(ServletContext sc) throws ServletException {
	
	    super.onStartup(sc);		
		sc.addListener(WebAppRootListener.class);
		sc.addListener(RequestContextListener.class);		
		sc.addListener(SingleSignOutHttpSessionListener.class);
		sc.addListener(Log4jConfigListener.class);
	
		String poserver = "poserver";
		Dynamic dn = sc.addServlet(poserver,
				com.zhuozhengsoft.pageoffice.poserver.Server.class);

		String[] urls = { "/poserver.do", "/pageoffice.cab", "/popdf.cab",
				"/sealsetup.exe", "/posetup.exe" };
		dn.addMapping(urls);

		String poseal = "poseal";
		dn = sc.addServlet(poseal,
				com.zhuozhengsoft.pageoffice.poserver.AdminSeal.class);
		String[] urls2 = { "/adminseal.do", "/loginseal.do", "/sealimage.do" };
		dn.addMapping(urls2);		
		Properties props = System.getProperties();
		props.setProperty("webenv", "true");
	}
	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[]{CommonConfig.class};
	}
	@Override
	protected Class<?>[] getServletConfigClasses() {
		
		return new Class<?>[]{WebMvcConfig.class};
	}
	@Override
	protected String[] getServletMappings() {
		return new String[]{"/mvc/"};
	}
}